package com.tedu.bill.demo1;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;

/**
 * Author：毕龙
 * Date: 2024/5/21 14:46
 */
public class TestQuestion17 {
    public static void main(String[] args) {

        ArrayList<Student> list = new ArrayList<Student>();
        list.add(new Student("Tom", 18, 100, "class05"));
        list.add(new Student("Jerry", 22, 70, "class04"));
        list.add(new Student("Owen", 25, 90, "class05"));
        list.add(new Student("Jim", 30, 80, "class05"));
        list.add(new Student("Steve", 28, 66, "class06"));
        list.add(new Student("Kevin", 24, 100, "class04"));

        int sumAge = 0;
        for (Student student : list) {
            sumAge += student.getAge();
        }
        System.out.println(sumAge/list.size());
        //装所有的班级
        HashSet<String> set = new HashSet<>();
        for (Student student : list) {
            set.add(student.getClassNum());
        }

        set.forEach(s->{
            double sumScore = 0;
            int countClassNum = 0;
            //遍历整个list集合中的所有学生
            for (Student student : list) {
                if(student.getClassNum().equals(s)){
                    //将该班级中的所有学生成绩相加
                    sumScore+=student.getScore();
                    //统计该班级有几个学生
                    countClassNum ++;

                }
            }
            System.out.println(s + "班级平均成绩："+(sumScore/countClassNum));
        });


    }
}
